class Task
  constructor: ->
    queries = {}
    queries.page = 1
    queries.location = "全部"
    $.each document.location.search.substr(1).split('&'), (c,q)->
      i = q.split('=')
      if i[1]
        queries[i[0].toString()] = i[1].toString()
    @_id = window.location.pathname.split('/')[2]
    @params =
      current_page: queries.page
      location:     queries.location
    @selected = []

  add_comment_tweet: (tweet) ->
    push_flag = true
    for _t in @selected
      push_flag = false if _t.wid == tweet.wid || (_t.uid == tweet.uid && tweet.uid != "" )
    @selected.push(tweet) if push_flag

  remove_comment_tweet: (tweet) ->
    _tweets = []
    for _t in @selected
      _tweets.push _t unless _t.wid == tweet.wid ||(_t.uid == tweet.uid && _t.uid.toString() != 'undefined')
    @selected = _tweets

  commit_comment: ->
    $.ajax
      url: ""
      type: "POST"
      data:
        wid:  $('#commit_tweet_id').val()
        uid:  $('#commit_user_id').val()
        reply: $('#comment_text').val()
      success: (retval) =>
        console.log retval
      error: (retval) ->
        console.log "error comment_weibos"
        console.log retval

window.task = new Task()

$(->

  $('.comment-btn').click ->
    _info = $(this).closest('li').attr('data').split('_')
    $("#commit_tweet_id").val(_info[0])
    $("#commit_user_id").val(_info[1])
    $("#comment_text").text("@" + _info[2])

  $('#commit_comment').click ->
    task.commit_comment()
    $("#myModal").modal('hide')
    false

)
